package com.azusa.xbiao.controller;

import com.azusa.xbiao.entity.Order;
import com.azusa.xbiao.entity.Result;
import com.azusa.xbiao.entity.StatusCode;
import com.azusa.xbiao.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 查询用户订单数据
     * @param uid
     * @return
     */
    @RequestMapping("findArrivalOrder/{uid}")
    public Result findArrivalOrder(@PathVariable("uid")int uid){
        return new Result(StatusCode.SUCCESS,orderService.findArrivalOrder(uid));
    }

    /**
     * 查询用户订单数据
     * @param uid
     * @return
     */
    @RequestMapping("findEvaluateOrder/{uid}")
    public Result findEvaluateOrder(@PathVariable("uid")int uid){
        return new Result(StatusCode.SUCCESS,orderService.findEvaluateOrder(uid));
    }

    /**
     * 订单确认到货
     * @param order
     * @return
     */
    @RequestMapping("confirmReceipt")
    public Result confirmReceipt(@RequestBody Order order){
        order.setArrival((byte) 1);
        order.setArrivalDate(new Date());
        orderService.save(order);
        return new Result(StatusCode.SUCCESS);
    }

    /**
     * 评价订单
     * @param order
     * @return
     */
    @RequestMapping("evaluate")
    public Result evaluate(@RequestBody Order order){
        order.setEvaluate((byte) 1);
        order.setEvaluateDate(new Date());
        orderService.save(order);
        return new Result(StatusCode.SUCCESS);
    }


}
